import {Component, OnInit, ViewEncapsulation} from '@angular/core';
import {PaymentService} from '@payment/payment.service';
import {ActivatedRoute, Params, Router} from "@angular/router";
import {AuthService} from "@shared/service/auth/auth.service";

import {imageUtil} from "@core/globals/globals.service";
import {ToolsService} from "@shared/service/tools/tools.service";
import {GoodsOrderRespVO, SNSResult} from "@interface/index";


@Component({
  selector: 'seed-payment-success',
  templateUrl: './sign-up-personal-progress.component.html',
  styleUrls: ['./sign-up-personal-progress.component.scss'],
  encapsulation: ViewEncapsulation.None
})
export class SignUpPersonalProgressComponent implements OnInit {
  public orderInfo: GoodsOrderRespVO;
  public params = {};
  private userId: string;
  public imageUtil = imageUtil.path;

  constructor(public toolsService: ToolsService,
              public route: ActivatedRoute,
              private authService: AuthService,
              private paymentService: PaymentService,
              private router: Router) {
    this.orderInfo = new GoodsOrderRespVO();
    this.userId = this.authService.getUserId();
  }

  getOrderInfo(params) {
    this.toolsService.showLoading();
    this.paymentService.getOrderInfo(params).subscribe((res: SNSResult<GoodsOrderRespVO>) => {
      this.toolsService.hideLoading();
      if (res.result === '0') {
        this.orderInfo = res.data;
      }
    });
  }


  handleDetail() {
    this.router.navigate(['/order/detail', this.params['orderNumber']]);
    /**, {queryParams: {orderId: this.params['orderNumber']}}*/
  }

  ngOnInit() {
    this.route.queryParams.subscribe((params: Params) => {
      this.params = params;
      this.getOrderInfo(params);
    });
  }
}
